<?php
namespace Admin\Controller;
use Think\Controller;
class GroupController extends CommonController {
    public function indexAction(){

    	$sql = "select count(id) count from auth_group";

        $count = current(M()->query($sql))['count'];

        $Page  = new \Think\Page($count,8);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show  = $Page->show();// 分页显示输出

    	$sql = "select * from auth_group  limit {$Page->firstRow},{$Page->listRows}";

    	$res = M()->query($sql);

    	foreach ($res as &$v) {
    		$sql = "select title from auth_rule where id in ({$v['rules']})";

    		 $arr = M()->query($sql);

    		 $str = '';

    		 foreach ($arr as $value) {
    		 	$str .= $value['title'].',';
    		 }

    		 $v['rules'] = $str;
    	}


        $this->assign('count',$count);
        $this->assign('show',$show);
    	$this->assign('res',$res);
       	$this->display();
    }


    public function addAction()
    {
        

    	if(IS_POST){

    		var_dump($_POST);

    	}else{
    		$sql = "select * from auth_rule_category";

	    	$categoryData = M()->query($sql);

	    	foreach ($categoryData as &$v) {

	    		$sql = "select * from auth_rule where cid = '{$v['id']}'";

	    		$v['son'] = M()->query($sql);
	    	}

	    	$this->assign('categoryData',$categoryData);

	    	$this->display();
    	}
    }

    
}